/**
 * Created by huxia on 2016/11/24.
 */

module.exports = function(sequelize, DataTypes) {
	var Doctor = sequelize.define('doctor', {
		id: {
			type: DataTypes.INTEGER,
			allowNull: false,
			unique: true,
			primaryKey: true
		},
		name: {
			type: DataTypes.STRING,
			allowNull: false
		},
		level: {
			type: DataTypes.ENUM,
			values: [1, 2, 3, 4],
			allowNull: false
		},
		hp_id: {
			type: DataTypes.INTEGER,
			allowNull: false
		},
		dpt_id: {
			type: DataTypes.INTEGER,
			allowNull: false
		},
		information: {
			type: DataTypes.STRING,
			allowNull: false
		}
	}, {
		underscore: true,
		'timestamps': false,
		'createdAt': false,
		'updatedAt': false
	}, {
        classMethods: {
            associate: function(models) {
                Doctor.belongsTo(models.Hospital, {
                    onDelete: "CASCADE",
                    onUpdate: "CASCADE",
                    foreignKey: {
                        allowNull: false
                    }
                });
                Doctor.belongsTo(models.Department,{
                    onDelete: "CASCADE",
                    onUpdate: "CASCADE",
                    foreignKey: {
                        allowNull: false
                    }
                });
                Doctor.hasMany(models.Outcall);
            }
        }
    });

	return Doctor;
};